package com.tlcx.kfip.ui;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;

import com.tlcx.kfip.R;
import com.tlcx.kfip.listener.FrescoImageLoader;
import com.youth.banner.Banner;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by victor on 2016/10/31 17:06.
 * Email:zhuzhaoyang@yuanchuangyun.com
 */

public class KfipAdsView extends LinearLayout {

    private Context mContext;
    private LayoutInflater mInflater;
    private List<Integer> bannerMocks;              //广告页假数据

    @BindView(R.id.banner_kfip)
    Banner adsBanner;

    public KfipAdsView(Context context) {
        super(context);
        init(context);
        addAdsData();
        setView();
    }

    public KfipAdsView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
        addAdsData();
        setView();
    }

    /**
     * 初始化
     */
    private void init(Context context){
        mContext = context;
        mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view = mInflater.inflate(R.layout.widget_kfip_ads,null,false);
        addView(view);
        ButterKnife.bind(this,view);
    }
    private void setView(){
        adsBanner.setImageLoader(new FrescoImageLoader(mContext));
        adsBanner.setImages(bannerMocks);
        adsBanner.start();
    }
    /**
     * 添加广告假数据
     */
    private void addAdsData(){
        if (bannerMocks == null) {
            bannerMocks = new ArrayList<>();
        }
        bannerMocks.add(R.mipmap.mock_ad_first);
        bannerMocks.add(R.mipmap.mock_ad_second);
        bannerMocks.add(R.mipmap.mock_ad_third);
    }
}
